package com.esri.core.geometry;

/* loaded from: classes.dex */
class IndexMultiDCList {
    AttributeStreamOfInt32 a;
    AttributeStreamOfInt32 b;
    int c;
    int d;
    int e;
    int f;
    int g;

    static int c() {
        return -1;
    }

    public IndexMultiDCList() {
        AttributeStreamOfInt32 attributeStreamOfInt32 = new AttributeStreamOfInt32(0);
        this.a = attributeStreamOfInt32;
        attributeStreamOfInt32.reserve(256);
        AttributeStreamOfInt32 attributeStreamOfInt322 = new AttributeStreamOfInt32(0);
        this.b = attributeStreamOfInt322;
        attributeStreamOfInt322.reserve(256);
        this.e = c();
        this.f = c();
        this.c = 0;
        this.d = 0;
        this.g = c();
    }

    void a(int i) {
        this.a.set(i + 0, -559038737);
        this.a.set(i + 2, this.e);
        this.e = i;
    }

    int a() {
        if (this.e != c()) {
            int i = this.e;
            this.e = this.a.get(i + 1);
            this.a.set(i + 1, c());
            this.a.set(i + 2, c());
            return i;
        }
        int size = this.a.size();
        this.a.add(c());
        this.a.add(c());
        this.a.add(c());
        return size;
    }

    void b(int i) {
        this.b.set(i, c());
        this.b.set(i + 1, this.f);
        this.b.set(i + 2, c());
        this.b.set(i + 3, c());
        this.f = i;
    }

    int b() {
        if (this.f != c()) {
            int i = this.f;
            this.f = this.b.get(i + 1);
            return i;
        }
        int size = this.b.size();
        this.b.add(c());
        this.b.add(c());
        this.b.add(c());
        this.b.add(c());
        this.b.add(0);
        this.b.add(0);
        return size;
    }

    void a(int i, int i2) {
        this.a.set(i + 1, i2);
    }

    void b(int i, int i2) {
        this.a.set(i + 2, i2);
    }

    void c(int i, int i2) {
        this.b.set(i + 4, i2);
    }

    void d(int i, int i2) {
        this.b.set(i + 3, i2);
    }

    void e(int i, int i2) {
        this.b.set(i + 2, i2);
    }

    public int createList(int i) {
        int b = b();
        this.b.set(b + 0, c());
        this.b.set(b + 1, c());
        this.b.set(b + 2, c());
        this.b.set(b + 3, this.g);
        this.b.set(b + 4, 0);
        this.b.set(b + 5, i);
        if (this.g != c()) {
            e(this.g, b);
        }
        this.d++;
        this.g = b;
        return b;
    }

    public int deleteList(int i) {
        clear(i);
        int i2 = this.b.get(i + 2);
        int i3 = this.b.get(i + 3);
        if (i2 != c()) {
            d(i2, i3);
        } else {
            this.g = i3;
        }
        if (i3 != c()) {
            e(i3, i2);
        }
        b(i);
        this.d--;
        return i3;
    }

    public int getListData(int i) {
        return this.b.get(i + 5);
    }

    public int addElement(int i, int i2) {
        return insertElement(i, c(), i2);
    }

    public int insertElement(int i, int i2, int i3) {
        int i4;
        int a = a();
        if (i2 != c()) {
            i4 = getPrev(i2);
            a(i2, a);
        } else {
            i4 = -1;
        }
        b(a, i2);
        if (i4 != c()) {
            b(i4, a);
        }
        int i5 = i + 0;
        if (i2 == this.b.get(i5)) {
            this.b.set(i5, a);
        }
        if (i2 == c()) {
            int i6 = i + 1;
            int i7 = this.b.get(i6);
            a(a, i7);
            if (i7 != -1) {
                b(i7, a);
            }
            this.b.set(i6, a);
        }
        this.c++;
        f(a, i3);
        c(i, getListSize(i) + 1);
        return a;
    }

    public int deleteElement(int i, int i2) {
        int prev = getPrev(i2);
        int next = getNext(i2);
        if (prev != c()) {
            b(prev, next);
        } else {
            this.b.set(i + 0, next);
        }
        if (next != c()) {
            a(next, prev);
        } else {
            this.b.set(i + 1, prev);
        }
        a(i2);
        c(i, getListSize(i) - 1);
        this.c--;
        return next;
    }

    public int getData(int i) {
        return this.a.get(i);
    }

    void f(int i, int i2) {
        this.a.set(i, i2);
    }

    public int getNext(int i) {
        return this.a.get(i + 2);
    }

    public int getPrev(int i) {
        return this.a.get(i + 1);
    }

    public int getFirst(int i) {
        return this.b.get(i);
    }

    public int getLast(int i) {
        return this.b.get(i + 1);
    }

    public void clear() {
        int firstList = getFirstList();
        while (firstList != -1) {
            firstList = deleteList(firstList);
        }
    }

    public void clear(int i) {
        int last = getLast(i);
        if (last != c()) {
            b(last, this.e);
            this.e = getFirst(i);
            this.c -= getListSize(i);
        }
    }

    public boolean isEmpty(int i) {
        return this.b.get(i) == c();
    }

    public boolean isEmpty() {
        return this.c == 0;
    }

    public int getListSize(int i) {
        return this.b.get(i + 4);
    }

    public int getNodeCount() {
        return this.c;
    }

    public int getListCount() {
        return this.d;
    }

    public int getFirstList() {
        return this.g;
    }

    public int getNextList(int i) {
        return this.b.get(i + 3);
    }
}
